import {
  GET_USERINFO,
  GET_OPENID,
  UPLOAD_USERINFO,
  CONFIRM_UPLOAD_USERINFO,
  CONFIRM_LOGIN
} from "../constants/user";

const INIT_STATE = {
  login: false
};

export default function user(state = INIT_STATE, action) {
  switch (action.type) {
    case GET_USERINFO:
      return { ...state, ...action.payload };
    case GET_OPENID:
      return { ...state, openid: action.payload.data.openid };
    case UPLOAD_USERINFO:
    let uploadUserInfo = action.payload.code,
    specialWords=action.payload.msg,
    data=action.payload.data?action.payload.data:{};
return { ...state, uploadUserInfo ,specialWords,...data};
    case CONFIRM_UPLOAD_USERINFO:
      return { ...state, login: state.uploadUserInfo === 0 };
    case CONFIRM_LOGIN:
      let { uploadUserInfo:deletedValue ,...newState} = state;
      return { ...newState };
    default:
      return state;
  }
}
